using Godot;
using System;
using Smr;

public partial class 组件战斗飘字 : Node2D
{
    [Signal] public delegate void 信号动画结束EventHandler();
    [Export] private Label 飘字;

    public int 数值;
    public Vector2 位置;
    public string 颜色 = "#ff0000";
    public bool 增减益 = false;
    public bool 是否暴击 = false;

    public override void _Ready()
    {
        Position = 位置;
        if (飘字 != null)
        {
            飘字.Text = 增减益 ? "+" + 数值 : "-" + 数值;
            飘字.LabelSettings = new LabelSettings
            {
                FontColor = new Color(颜色),
                ShadowColor = new Color("#fff"),
                OutlineColor = new Color("#fff"),
                OutlineSize = 20,
                FontSize = 60
            };
            if (是否暴击)
            {
                飘字.Text = "暴 " + 飘字.Text;
            }
            动画();
        }
    }

    private async void 动画()
    {
        Tween 补间动画 = CreateTween().BindNode(this);
        补间动画.SetParallel();
        补间动画.TweenProperty(this, "position:y", Position.Y - 40, 0.5 * 配置.战斗加速[游戏存档.战斗加速]);
        补间动画.TweenProperty(this, "modulate", new Color(1, 0, 0, 0), 0.5 * 配置.战斗加速[游戏存档.战斗加速]);
        await ToSignal(补间动画, Tween.SignalName.Finished);
        QueueFree();
        EmitSignal(SignalName.信号动画结束);
    }
}
